import java.util.concurrent.*;

public class Main {
    public static void main(String[] args) {
        ThreadPoolExecutor pool
                = new ThreadPoolExecutor(
                3,
                5,
                8,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        // 核心线程数
        // 最大线程数 = 核心线程数 + 临时线程数
        // 临时线程最大空闲时间
        // 时间单位
        // 等待队列数
        // 线程工厂
        // 拒绝策略


        MyRunnable myRunnable = new MyRunnable();

        // 占满三个核心线程
        pool.execute(myRunnable);
        pool.execute(myRunnable);
        pool.execute(myRunnable);

        // 占满四个队列
        pool.execute(myRunnable);
        pool.execute(myRunnable);
        pool.execute(myRunnable);
        pool.execute(myRunnable);

        // 创建临时线程
        pool.execute(myRunnable);
        pool.execute(myRunnable);

        // 拒绝策略
        pool.execute(myRunnable);
    }
}
